package util;

import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.Properties;

public class PropertiesUtils implements Serializable {
    private static final String DEFAULT_PROPERIES_FILE = "application.properties";

    /**
     * 按key获取值
     *
     * @param key
     * @return
     */
    public static String getProperty(String key) {
        Properties properties = getProperties();
        return properties.getProperty(key);
    }

    /**
     * 获取整个配置信息
     *
     * @return
     */
    public static Properties getProperties() {
        Properties properties = new Properties();
        InputStream is = null;
        try {
            is = PropertiesUtils.class.getClassLoader().getResourceAsStream(DEFAULT_PROPERIES_FILE);
            properties.load(is);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return properties;
    }

}
